package com.xigua._递归;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 假设把某股票的价格按照时间先后顺序存储在数组中，请问买卖该股票一次可能获得的最大利润是多少？
 * @date 2022/3/923:58
 */
public class _剑指_Offer63_股票的最大利润 {

    public static void main(String[] args) {
        int[] prices =  new int[]{7,3,9,1,6,4,8,12};
    }

    public int maxProfit(int[] prices) {
        if (prices == null||prices.length == 0 )return 0;
        int max = Integer.MIN_VALUE;
        int prePrice = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if (prices[i]>prePrice){
                max = Math.max(prices[i]-prePrice,max);
            }else {
                prePrice = prices[i];
            }
        }
        return Math.max(0,max);
    }

}
